<template>
    <Form ref="formValidate" :model="formValidate" :rules="ruleValidate" :label-width="70" label-position="right">
        <FormItem label="导游名称" prop="name">
            <Input type="text" v-model="formValidate.name"></Input>
        </FormItem>      
        <FormItem label="联系电话">
            <Input type="text" v-model="formValidate.phone"></Input>
        </FormItem> 
        <FormItem>
            <Button type="primary" @click="handleSubmit('formValidate')">确定</Button>
        </FormItem>
    </Form>
</template>
<script>

export default {
    name: 'guideinfo',
    props: ['formValidate'],
    data(){
        return { 
            ruleValidate:{
                name:[
                    { required: true, message: '请输入导游名称', trigger: 'blur' }
                ]                
            }       
        }
    },   
    methods: { 
        addGuide(){
            this.$axios({
                mothod: 'post',
                url: 'http://localhost/public/api/guide/create',
                params: this.formValidate
            }).then((response)=> { 
                this.$Message.success('录入成功!'); 
            })
            .catch(function (error) {
                this.$Message.error('录入失败!');
            });   
        },
        editGuide(){
            this.$axios({
                mothod: 'post',
                url: 'http://localhost/public/api/guide/update',
                params: this.formValidate
            }).then((response)=> { 
                this.$Message.success('编辑成功!'); 
            })
            .catch(function (error) {
                this.$Message.error('编辑失败!');
            });   
        },                 
        handleSubmit(name){                 
            this.$refs[name].validate((valid) => {                   
                if (valid) {                                 
                    if(this.formValidate.id != ""){
                        this.editGuide(); 
                    }else{
                        this.addGuide();                                 
                    }  
                    this.$emit('updateGuideList');    
                    this.$emit('closeDialog');              
                } else {
                    this.$Message.error('提交失败!');
                }
            })
        }
    }
}
</script>
